const register = localStorage.getItem("register")
let newArr = JSON.parse(register)

// 1. 实现 账户登录 和  二维码登录 的 tab栏切换  高亮的类为 active
document.querySelector(".tab-nav").addEventListener("click", function (e) {

    if (e.target.tagName === "A") {
        document.querySelector(".tab-nav a.active").classList.remove("active")
        e.target.classList.add("active")
        if (e.target.dataset.id === "1") {
            document.querySelectorAll(".tab-pane")[0].style.display = "none"
            document.querySelectorAll(".tab-pane")[1].style.display = "block"
        } else {
            document.querySelectorAll(".tab-pane")[0].style.display = "block"
            document.querySelectorAll(".tab-pane")[1].style.display = "none"
        }
    }
})
// 2. 实现 短信登录 和  账号登录 的 切换
let count = 0
const linkList = document.querySelector(".link")
linkList.addEventListener("click", function (e) {
    if (e.target.tagName === "A") {
        count++
        if (count % 2 === 0) {
            linkList.querySelectorAll("a")[1].style.display = "none"
            linkList.querySelectorAll("a")[0].style.display = "block"
            document.querySelectorAll(".tab-username")[1].style.display = "none"
            document.querySelectorAll(".tab-username")[0].style.display = "block"
        }
        else {
            linkList.querySelectorAll("a")[0].style.display = "none"
            linkList.querySelectorAll("a")[1].style.display = "block"
            document.querySelectorAll(".tab-username")[0].style.display = "none"
            document.querySelectorAll(".tab-username")[1].style.display = "block"
        }
    }
})
// 3. 提交时判断有没有勾选同意协议
document.querySelector(".button button").addEventListener("click", function (e) {
    e.preventDefault()
    const checkBox = document.querySelector(".remember")
    if (checkBox.checked !== true) {
        alert("请勾选同意按钮")
    } else {

        for (let i = 0; i < newArr.length; i++) {
            const uname = document.querySelector("input[name='username']")
            const password = document.querySelector("input[name='password']")
            //const phone = document.querySelector("input[name='phonenum']")
            if (uname.value !== newArr[i].uname) {
                alert("用户名不正确")
                return
            }
            if (password.value !== newArr[i].password) {
                alert("密码不正确")
                return
            }
            /*   if (phone.value !== newArr[i].phone) {
                  alert("手机号不正确")
                  return
              } */
            let unameValue = uname.value
            localStorage.setItem("uname", unameValue)
        }

        location.href = "../index.html"

    }
})

// 4. 发送短信验证码模块
const code = document.querySelector('.pane-code')
// 节流阀
let flag = true//为防止多次点击
code.addEventListener('click', function () {
    if (flag) {
        flag = false
        let time = 10
        code.innerHTML = `${time}s重新获取`
        let timeid = setInterval(function () {
            time--
            if (time) {
                flag = false
                time = time < 10 ? "0" + time : time
                code.innerHTML = `${time}s重新获取`
            } else {
                clearInterval(timeid)
                flag = true
                code.innerHTML = `发送验证码`
            }
        }, 1000)
    }
})


// 校验传值


